package com.nidu.demo.dict.executor.query;

import com.alibaba.cola.dto.PageResponse;
import com.nidu.demo.dict.convertor.DictTypeCriteriaConvertor;
import com.nidu.demo.dict.dto.DictTypePageQry;
import com.nidu.demo.dict.convertor.DictTypeConvertor;
import com.nidu.demo.dict.dto.DictTypeCO;
import com.nidu.demo.dict.gateway.DictTypeGateway;
import com.nidu.demo.dict.model.DictType;
import com.nidu.demo.dict.model.DictTypeCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 字典类型分页查询执行器
 *
 * @author auto
 */
@Component
@RequiredArgsConstructor
public class DictTypePageQryExe {

    private final DictTypeGateway gateway;

    private final DictTypeConvertor convertor;

    private final DictTypeCriteriaConvertor criteriaConvertor;

    public PageResponse<DictTypeCO> execute(DictTypePageQry qry) {
        DictTypeCriteria criteria = criteriaConvertor.toDataObject(qry);
        PageResponse<DictType> page = gateway.pageByCondition(criteria);
        List<DictTypeCO> dictTypeCOS = convertor.toClientObjects(page.getData());
        return PageResponse.of(dictTypeCOS, page.getTotalCount(), page.getPageSize(), page.getPageIndex());
    }
}